<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <!-- 十进制转二进制 -->
    <!-- 
        num = 1011
        1*2^0+1*2^1+0*2^2+0*2^3+1*2^4
     -->
    <script>
        var num = 1011;
        var str = (num+"").split("").reverse()
        var sum = 0;
        for(var i =0 ;i<str.length;i++){
            sum += str[i]*Math.pow(2,i)
        }
        console.log(sum)
    </script>
</body>
</html>